home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / noweb / src / c / columns.c < prev    next >
C/C++ Source or Header  |  1995-02-24  |  821b  |  33 lines

  1. #line 19 "columns.nw"
  2. #include <stdio.h>
  3. #include "columns.h"
  4.  
  5. int tabsize = 8;
  6. #line 24 "columns.nw"
  7. int columnwidth (char *s) {             /* width of a string in columns */
  8.   return limitcolumn(s, 0);
  9. }
  10. #line 29 "columns.nw"
  11. int limitcolumn (char *s, int col) {
  12.     while (*s) {
  13.         col++;
  14.         if (*s=='\t' && tabsize > 0) while (col % tabsize != 0) col++;
  15.         s++;
  16.     }
  17.     return col;
  18. }
  19. #line 39 "columns.nw"
  20. void indent_for (int width, FILE *fp) { 
  21.                                 /* write whitespace [[width]] columns wide */
  22. /*fprintf(fp,"<%2d>",width); if (width>4) {fprintf(fp,"    "); width -= 4;}*/
  23.     if (tabsize > 1)
  24.         while (width >= tabsize) {
  25.             putc('\t', fp);
  26.             width -= tabsize;
  27.         }
  28.     while (width > 0) {
  29.         putc(' ', fp);
  30.         width--;
  31.     }
  32. }
  33.